home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbsqueez / vbsqz.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  11.6 KB  |  215 lines

  1. VERSION 2.00
  2. Begin Form VBSqueeze 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "VB Squeeze"
  6.    ClientHeight    =   405
  7.    ClientLeft      =   1110
  8.    ClientTop       =   1545
  9.    ClientWidth     =   1725
  10.    Height          =   810
  11.    Left            =   1050
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   405
  17.    ScaleWidth      =   1725
  18.    Top             =   1200
  19.    Width           =   1845
  20.    Begin CommandButton btnSave 
  21.       Caption         =   "&Save/Load Text"
  22.       Height          =   375
  23.       Left            =   15
  24.       TabIndex        =   0
  25.       Top             =   15
  26.       Width           =   1695
  27.    End
  28. '*************************************************************'
  29. '*                         VB SQUEEZE                        *'
  30. '*                                                           *'
  31. '*  What is it?                                              *'
  32. '*  VB Squeeze is another useful(hopefully) little utility   *'
  33. '*  that will save some of you some time and make your life  *'
  34. '*  a little easier.                                         *'
  35. '*                                                           *'
  36. '*  What does it do?                                         *'
  37. '*  We all know that VB accumualates extra garbage in our    *'
  38. '*  Form files, and such, while we work, and the only way to *'
  39. '*  get rid of it is to do a SaveText/LoadText for each of   *'
  40. '*  our forms.  This can get to be very tedious indeed, so   *'
  41. '*  VB Squeeze will do it for you, for each file in your     *'
  42. '*  project.                                                 *'
  43. '*                                                           *'
  44. '*  How does it work?                                        *'
  45. '*  VB Squeeze uses SendKeys to activate VB and perform the  *'
  46. '*  necessary operations on each file.                       *'
  47. '*                                                           *'
  48. '*  WARNING!                                                 *'
  49. '*  I just got this idea and wanted to see if it would       *'
  50. '*  work so I threw it together very quickly. The code is    *'
  51. '*  commented but you will want to look it over for obvious  *'
  52. '*  bugs that I missed and places to improve it(like error   *'
  53. '*  checking of some sort). Since it relies on SendKeys it   *'
  54. '*  is not the most reliable method of doing this but, hey,  *'
  55. '*  it works. USE IT AT YOUR OWN RISK. If you modify and     *'
  56. '*  improve it I would love to hear about it. If you think   *'
  57. '*  it's a lousy idea and a complete waste of time I want    *'
  58. '*  to know that too.                                        *'
  59. '*                                                           *'
  60. '*  PLEASE!                                                  *'
  61. '*  Look through the code before you run it(and don't use    *'
  62. '*  it on anything important at first) so you know what it   *'
  63. '*  does to get the job done. You may want to modify it to   *'
  64. '*  operate on a single file instead of all the files in     *'
  65. '*  your project.                                            *'
  66. '*                                                           *'
  67. '*  NOTES:                                                   *'
  68. '*  The biggest note is this. If you have two files with     *'
  69. '*  the same prefix(i.e. MYAPP.FRM & MYAPP.BAS) then         *'
  70. '*  VB Squeeze will stop if they are consecutive in the      *'
  71. '*  project window(the global file seems to be the biggest   *'
  72. '*  culprit). The reason is this. As VB Squeeze moves down   *'
  73. '*  the list of files in the project window it compares the  *'
  74. '*  name of the last file with that of the current file,     *'
  75. '*  and, if they match, it assumes it's at the last file.    *'
  76. '*  I hope someone comes up with a better method for this.   *'
  77. '*                                                           *'
  78. '*  Why does only the prefix need to match? The filename is  *'
  79. '*  taken from the Code|Save dialog box and .TXT is appended *'
  80. '*  automatically.                                           *'
  81. '*                                                           *'
  82. '*  Error checking doesn't exist. You will want to add this  *'
  83. '*  for safety(check for pre-existing files and such).       *'
  84. '*                                                           *'
  85. '*  IMPROVEMENTS:                                            *'
  86. '*  Please do!  I don't have the time to really make this a  *'
  87. '*  priority project and I HATE doing the SaveText/LoadText  *'
  88. '*  mambo.                                                   *'
  89. '*                                                           *'
  90. '*  Maybe the saved text could be opened and all the         *'
  91. '*  comments and blank lines could be stripped to comapct    *'
  92. '*  code before compilation.                                 *'
  93. '*                                                           *'
  94. '*  Comments? Suggestions? I want 'em!                       *'
  95. '*                                                           *'
  96. '*  Gregg Irwin CIS:ID 72450,676                             *'
  97. '*************************************************************'
  98. DefInt A-Z
  99. Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
  100. Declare Function GetActiveWindow Lib "User" () As Integer
  101. Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal nMaxChars As Integer) As Integer
  102. Declare Function SetActiveWindow Lib "User" (ByVal hWnd As Integer) As Integer
  103. 'Const NULL = 0&      '--If you want to pass NULL to FindWindow
  104. Dim FileName As String
  105. Dim OldFileName As String
  106. Sub btnSave_Click ()
  107.                                                     '-- Class name for VB = "wndclass_desked_gsk"
  108.                                                     '-- Caption for VB    = "Microsoft Visual Basic [design]"
  109.     VBhWnd = FindWindow("wndclass_desked_gsk", "Microsoft Visual Basic [design]")
  110.      
  111.     If Len(VBhWnd) Then                             '-- Make sure VB is running before we do anything
  112.         ActivehWnd = GetActiveWindow()
  113.         If VBhWnd <> ActivehWnd Then                '-- If VB isn't active then activate it.
  114.             PrevhWnd = SetActiveWindow(VBhWnd)      '-- Save the handle of the currently active window
  115.         End If                                      '   and activate VB.
  116.         
  117.         Clipboard.Clear                             '-- Start with a clean clipboard
  118.         OldFileName = "!@#$%^&*()"                  '-- Initialize OldFileName so we don't have
  119.                                                     '   a match by accident or coinicidence.
  120. '------------------------------------------------------
  121. '-- Move to first file in project window
  122. '------------------------------------------------------
  123.         Do
  124.             SendKeys "%{F6}", True                  '-- Move to next VB owned window
  125.             WndCaption$ = Space$(13)                '-- Initialize a string for an API call
  126.             RtnLen = GetWindowText(GetActiveWindow(), WndCaption$, 12) '-- Get Window caption
  127.             WndCaption$ = Left$(WndCaption$, RtnLen)        '-- Strip Chr$(0)
  128.             If Right$(WndCaption$, 3) = "MAK" Then Exit Do  '-- We found the project window
  129.         Loop
  130.         SendKeys "{HOME}"                           '-- Move to first file
  131.         
  132. '------------------------------------------------------
  133. '-- For each file in the project...
  134. '    Save the code as text and then reload it to get
  135. '    rid of all the old trash that hangs around.
  136. '------------------------------------------------------
  137.         Do While OldFileName <> FileName
  138.             OldFileName = FileName                  '-- Reset file name for next iteration
  139.                                             
  140.             SendKeys "%CS", True                    '-- Code|Save
  141.              x = DoEvents()
  142.             
  143.             SendKeys "^{INSERT}{ENTER}", True       '-- Clip filename to clipboard & Save txt file
  144.              x = DoEvents()
  145.             
  146.             FileName = Clipboard.GetText(1)         '-- Save filename in variable
  147.             
  148. '------------------------------------------------------
  149. '-- Find the project window
  150. '------------------------------------------------------
  151.             Do
  152.                 SendKeys "%{F6}", True              '-- Move to next VB owned window
  153.                 WndCaption$ = Space$(13)            '-- Initialize a string for an API call
  154.                 RtnLen = GetWindowText(GetActiveWindow(), WndCaption$, 12) '-- Get Window caption
  155.                 WndCaption$ = Left$(WndCaption$, RtnLen)        '-- Strip Chr$(0)
  156.                 If Right$(WndCaption$, 3) = "MAK" Then Exit Do  '-- We found the project window
  157.             Loop
  158.              x = DoEvents()
  159.             
  160. '------------------------------------------------------
  161. '-- If you don't open the code window before loading
  162. '   the text it will load as a separate module.
  163. '------------------------------------------------------
  164.             SendKeys "{F7}", True                   '--Open code window
  165.              x = DoEvents()
  166.             
  167.             SendKeys "%CL", True                    '--Code|Load
  168.              x = DoEvents()
  169.             
  170.             SendKeys "+{INSERT}%R", True            '--Paste filename & Click "&Replace"
  171.              x = DoEvents()
  172.             
  173. '------------------------------------------------------
  174. '-- Close the window before moving to the next file
  175. '   otherwise the focus won't be in the project
  176. '   window(and you're in big trouble then).
  177. '------------------------------------------------------
  178.             SendKeys "% %{F4}"                      '--System Menu|Close
  179.              x = DoEvents()
  180. '****************************************************************'
  181. '*                                                              *'
  182. '*  NOTE:  The File|Save command is commented out for good      *'
  183. '*         reason. As I was working on this I ran the program   *'
  184. '*         to test it and it ate my file(becuase it loads the   *'
  185. '*         text in over the original file code). I consider     *'
  186. '*         this to be a bad thing. I recommend that you let it  *'
  187. '*         Save/Load-Text all your files and then look at them  *'
  188. '*         to make sure it all worked *before* you save them.   *'
  189. '*         This is a quick hack with very little planning and   *'
  190. '*         forethought behind it. MAKE NO ASSUMPTION THAT IT    *'
  191. '*         IS A FULLY TESTED PROGRAM THAT WILL WORK FOR YOU!!!  *'
  192. '*         I say this because it works on your entire project   *'
  193. '*         and could destroy a lot of work.  I am posting this  *'
  194. '*         app and all it's source in the hopes that someone    *'
  195. '*         will find it useful(and maybe improve it as well).   *'
  196. '*         I don't have time right now to make it bulletproof.  *'
  197. '*                                                              *'
  198. '****************************************************************'
  199.             
  200.             '**SendKeys "%FS", TRUE                   '--File|Save
  201.             
  202.             SendKeys "{DOWN}", True                 '--Move to next file
  203.         Loop
  204.               
  205.     Else
  206.         MsgBox "Visual Basic is not running", MB_OK, "VB Squeeze...Didn't"
  207.     End If 'Len(VBhWnd)
  208.      '-- Un-REM this to re-activate the window that was
  209.      '   active when we started.
  210.     'dummy = SetActiveWindow(PrevhWnd)
  211. End Sub
  212. Sub Form_Unload (Cancel As Integer)
  213.     End
  214. End Sub
  215.